package cn.iocoder.yudao.module.erp.controller.admin.giitem.giitemyw;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.erp.controller.admin.giitem.giitemyw.vo.*;
import cn.iocoder.yudao.module.erp.dal.dataobject.giitem.GiItemYwDO;
import cn.iocoder.yudao.module.erp.service.giitem.GiItemYwService;

@Tag(name = "管理后台 - ERP物流义乌仓库货号详情")
@RestController
@RequestMapping("/erp/gi-item-yw")
@Validated
public class GiItemYwController {

    @Resource
    private GiItemYwService giItemYwService;

    @PostMapping("/create")
    @Operation(summary = "创建ERP物流义乌仓库货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-yw:create')")
    public CommonResult<String> createGiItemYw(@Valid @RequestBody GiItemYwSaveReqVO createReqVO) {
        return success(giItemYwService.createGiItemYw(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新ERP物流义乌仓库货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-yw:update')")
    public CommonResult<Boolean> updateGiItemYw(@Valid @RequestBody GiItemYwSaveReqVO updateReqVO) {
        giItemYwService.updateGiItemYw(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除ERP物流义乌仓库货号详情")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-yw:delete')")
    public CommonResult<Boolean> deleteGiItemYw(@RequestParam("id") Long id) {
        giItemYwService.deleteGiItemYw(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得ERP物流义乌仓库货号详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-yw:query')")
    public CommonResult<GiItemYwRespVO> getGiItemYw(@RequestParam("id") Long id) {
        GiItemYwDO giItemYw = giItemYwService.getGiItemYw(id);
        return success(BeanUtils.toBean(giItemYw, GiItemYwRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得ERP物流义乌仓库货号详情分页")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-yw:query')")
    public CommonResult<PageResult<GiItemYwRespVO>> getGiItemYwPage(@Valid GiItemYwPageReqVO pageReqVO) {
        pageReqVO.setPageSize(-1);
        PageResult<GiItemYwDO> pageResult = giItemYwService.getGiItemYwPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, GiItemYwRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出ERP物流义乌仓库货号详情 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-yw:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportGiItemYwExcel(@Valid GiItemYwPageReqVO pageReqVO,
                                    HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<GiItemYwDO> list = giItemYwService.getGiItemYwPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "ERP物流义乌仓库货号详情.xls", "数据", GiItemYwRespVO.class,
                BeanUtils.toBean(list, GiItemYwRespVO.class));
    }

}